package com.example.design.adapter;

public class BinarySearch {
	public int binarySearch(int[] array, int key) {
		System.out.println("binary----search");
		int low = 0; 
		int high = array.length - 1;
		while(low <= high) {
			int middle = (low + high) /2;
			if(array[middle] < key) 
				low = middle + 1;
			else if(array[middle] > key) 
				high = middle - 1;
			else 
				return middle; //找到
		}
		return -1;//未找到
	}
}
